/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/
#include "com_hal.h"
#include "comtask.h"
#include "osObjects.h"   
#include "cominfo.h"
#include "dataproc.h"
#include "iap.h"

void CmdProc(void);
void WifiCmd(void);
void Cifsr(void);
void ComStringHandle(void);
osEvent ComEventInfo;

/*****************************************************************************//*!
* @brief   	com task init .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void ComTask(void const *argument)
{
//	uint16_t Cnt;
	
	ComInit(MB_BAUD_9600, MB_PAR_NONE);

	while (1)
	{
		// Insert thread code here...
		ComEventInfo = osSignalWait (0, COMDLYTIMEOUT);
		if( COM_EVENT_RCVEND == ComEventInfo.value.signals)
		{
			ComStringHandle();
		}
		else if(0 == ComEventInfo.value.signals)
		{
			//task delay time out
			TimeToAscii(&TimeCur, ComBuff);
			ComBuff[19] = '\r';
			ComBuff[20] = '\n';
			ComBuff[21] = 0;
			ComStringSend(ComBuff);
		}
	}
}

/*****************************************************************************//*!
* @brief   	String Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void ComStringHandle(void)
{
	switch(ComBuff[0])
	{
		//case 'A': WifiCmd();break;
		case ':': CmdProc(); break;
		default : break;
	}
	
	ComRcvSt = MB_RX_IDLE;
	ComRcvCnt = 0;
}

/*****************************************************************************//*!
* @brief   	Data Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void ComDataHandle(void)
{

}

/*****************************************************************************//*!
* @brief   Command Proc .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void CmdProc()
{
	uint8_t Cnt;
	
	if(CMD_START != ComBuff[0])
		return;
	
	switch(ComBuff[1])
	{
		case 'T': 	Cnt = 0;
					while(ComInfo[COM_INFO_TEST][Cnt])
					{
						ComBuff[Cnt] = ComInfo[COM_INFO_TEST][Cnt];
						Cnt++;
					}
					ComBuff[Cnt] = 0;
					ComStringSend(ComBuff);
					break;	
		case 'V': 	Cnt = 0;
					while(ComInfo[COM_INFO_VER][Cnt])
					{
						ComBuff[Cnt] = ComInfo[COM_INFO_VER][Cnt];
						Cnt++;
					}
					ComBuff[Cnt] = 0;
					ComStringSend(ComBuff);
					break;	
		default :   break;
	}
}


